package com.kehao.controller;

import com.baomidou.mybatisplus.extension.service.IService;
import com.kehao.pojo.Student;
import com.kehao.vo.StudentRec;
import com.kehao.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Api(tags = "接口模块类描述说明")：该注解标注在接口模块类上，用于对接口模块类进行描述说明
 * @ApiOperation(value="接口方法简要说明",notes="接口方法详细描述",response=Class<T>)：
 * 该注解标注在接口模块类的接口方法上，用于对接口方法进行描述说明。其中notes字段可以插入HTML标签，response字段表示该方法的返回值类型。
 * @ApiImplicitParams(list=[ ])：该注解作用在接口方法上，是ApiImplicitParam的列表
 * @ApiImplicitParam(name="参数名称",value = "参数说明",defaultValue = "参数默认值",dataType = "数据类型")：
 * 该注解作用于ApiImplicitParams列表内，用于对方法上的参数进行描述说明。
 */
@Api(tags = "学生请求ControllerApi")
@RestController
@RequestMapping("/students")
@RequiredArgsConstructor
public class StudentController{

    private final StudentService studentService;

    //增
    @ApiOperation(value = "添加学生方法", response = void.class)
    @PostMapping
    public void addStudent(@RequestBody Student student) {

//        studentService.addStudent(student);

        //mp
        studentService.save(student);

    }

    // 删
    @ApiOperation(value = "删除学生方法", response = void.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "学生id",defaultValue = "1",dataType = "Integer"),
//            @ApiImplicitParam(name="userInfo",value = "用户信息",defaultValue = "nothing",dataType = "String")
    })
    @DeleteMapping()
    public void delStudent(@RequestParam("id") Integer id) {

        studentService.del(id);

        //mp


    }

    // 改
    @ApiOperation(value = "修改学生方法", response = void.class)
    @PutMapping
    public void updateStudent(@RequestBody Student student) {

        studentService.update(student);

    }

    // 查 --> 全部
    @ApiOperation(value = "查询所有学生方法", response = List.class)
    @GetMapping()
    public List<StudentRec> getAllStudent() {

        return studentService.getAllStudent();

    }

    // 查 --> 单个，根据id查
    @ApiOperation(value = "查询单个学生方法", response = StudentRec.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "学生id",defaultValue = "1",dataType = "Integer"),
//            @ApiImplicitParam(name="userInfo",value = "用户信息",defaultValue = "nothing",dataType = "String")
    })
    @GetMapping("/{id}")
    public StudentRec getOneStudent(@PathVariable Integer id) {

        return studentService.getOneStudent(id);

    }


}
